package com.room.search.repository;

import com.room.search.domain.RoomUser;
import com.room.search.domain.User;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.jpa.repository.*;
import org.springframework.stereotype.Repository;

import java.util.Optional;

/**
 * Spring Data SQL repository for the RoomUser entity.
 */
@SuppressWarnings("unused")
@Repository
public interface RoomUserRepository extends JpaRepository<RoomUser, Long>,JpaSpecificationExecutor<RoomUser> {

    String USERS_BY_LOGIN_CACHE = "usersByLogin";

    Optional<RoomUser> findByMobile(String mobile);

    Optional<RoomUser> findByAccount(String account);

    @EntityGraph(attributePaths = "authorities")
    @Cacheable(cacheNames = USERS_BY_LOGIN_CACHE)
    Optional<RoomUser> findOneWithAuthoritiesByAccount(String account);

    Optional<RoomUser> findByAccountOrMobile(String account, String mobile);
}
